package day12;

public class Master {

    //多态的引用 Pet pet = new Dog();
    //工厂设计模式

    /**
     * 领养宠物
     * @param type
     * @return
     */
    public Pet getPet(String type){
        if(type.equals("Dog")){
            Dog dog = new Dog("阿旺",100,100,"二哈");
            return dog;
        } else if (type.equals("penguin")) {
            Penguin penguin = new Penguin("Q妹",100,100,"女");
            return penguin;
        }else {
            Cat cat = new Cat("喵喵",100,100,"睡觉");
            return cat;
        }
    }

    public void feed(Pet pet){
        pet.eat();
    }

    public void cure(Pet pet){
        pet.toHospital();
    }

    public void play(Pet pet){
        // 判断类型  pet 具体是什么类型
        // 对象 instanceof 类型
        //判断一个对象是否是某种类型
        if(pet instanceof Penguin){
            Penguin penguin = (Penguin) pet;
            penguin.youyong();
        }
        if(pet instanceof Dog){
            Dog dog = (Dog)pet;
            dog.jiefeipan();
        }
        if(pet instanceof Cat){
            Cat cat = (Cat)pet;
            cat.lumao();
        }

    }
}
